<?php
require_once "./mysql.php";
$Admin = $_REQUEST["admin"];
$Pass = $_REQUEST["pass"];
$Token = $_REQUEST["token"];


if (!isset($Admin) || !isset($Pass) || !isset($Token)) {
    exit(json_encode([
        "code" => 0,
        "msg" => "不能留空"
    ],JSON_UNESCAPED_UNICODE));
}

//查询语句
/** @var PDO $pd */
$statement = $pd->query("SELECT * FROM admin WHERE admin = '$Admin' AND pass = md5('$Pass')");
if (!(count($statement->fetchAll()) > 0)){
    exit(json_encode([
        "code" => 0,
        "msg" => "管理员账号密码错误"
    ],JSON_UNESCAPED_UNICODE));
}

$query = "DELETE FROM token WHERE admin = '$Admin' AND token = '$Token'";
$result = $pd->query($query);
if(count($result->fetchAll())> 0){
    exit(json_encode([
        "code" => 1,
        "msg" => "删除成功"
    ],JSON_UNESCAPED_UNICODE));
}
exit(json_encode([
    "code" => 0,
    "msg" => "删除失败"
],JSON_UNESCAPED_UNICODE));
